package com.cloud.easy.im.handler.qos;

/**
 * @author wangjian
 * @version 0.1.0
 * @create 2020年10月10日8:07 下午
 */
public class QoS4SendDaemonS2C extends QoS4SendDaemonRoot {

    private static QoS4SendDaemonS2C.Builder builder = new QoS4SendDaemonS2C.Builder();

    public QoS4SendDaemonS2C(Builder builder) {
        super(builder.chechInterval, builder.minMessageQosTime, builder.qosTryCount, builder.tag);
    }

    /**
     * 单利对象
     */
    private static class SingletonHolder {
        private static final QoS4SendDaemonS2C INSTANCE = new QoS4SendDaemonS2C(builder);
    }

    public static QoS4SendDaemonS2C getInstance() {
        return QoS4SendDaemonS2C.SingletonHolder.INSTANCE;
    }


    /**
     * 单利对象构建参数
     */
    static class Builder {
        /**
         * 执行间隔时间
         */
        private int chechInterval = 5;
        /**
         * 每条数据的最小qos时间
         */
        private int minMessageQosTime = 2 * 1000;
        /**
         * qos最大尝试次数
         */
        private int qosTryCount = 1;
        private String tag = "-本机qos";

        public Builder() {
        }

        public Builder(int chechInterval
                , int minMessageQosTime
                , int qosTryCount
                , String tag) {
            this.chechInterval = chechInterval;
            this.minMessageQosTime = minMessageQosTime;
            this.qosTryCount = qosTryCount;
            this.tag = tag;
        }
    }

    public static QoS4SendDaemonS2C setBuilder(int chechInterval
            , int minMessageQosTime
            , int qosTryCount
            , String tag) {
        builder = new QoS4SendDaemonS2C.Builder(chechInterval, minMessageQosTime, qosTryCount, tag);
        return getInstance();
    }
}
